package org.example.studyonline.controller;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.example.studyonline.pojo.Product;
import org.example.studyonline.pojo.Result;
import org.example.studyonline.service.Impl.ProductServiceImpl;
import org.example.studyonline.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductServiceImpl productService;
    @RequiresAuthentication
    @GetMapping("/pay/{productID}")
    public Result pay(@PathVariable Integer productID){
        if (productService.pay(productID) == false)
            return Result.error("支付失败");
        else
            return Result.success("支付成功",null);
    }

    @GetMapping("/vip/list")
    public Result<List<Product>> getVIPproduct(){
        List<Product> products = productService.getVIPproduct();
        return Result.success("获取VIP产品成功",products);
    }

}
